package com.ycb.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ycb
 * @Version 1.0
 * @Date 2024/10/3 17:32
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code; //1.成功，其余数字失败
    private String msg;
    private T data;

    //不过此种方式的复用性更高
    public static <T> Result<T> success(T obj){
        Result<T> r = new Result<>();
        r.setCode(1);
        r.setData(obj);
        return r;
    }

    public static <T> Result<T> error(String msg){
        Result<T> r = new Result<>();
        r.setCode(0);
        r.setMsg(msg);
        return r;
    }
}
